<!--
 * @Descripttion: |
 * @version: 1.0
 * @Author: 王娆
 * @Date: 2020-08-23 02:16:16
 * @LastEditors: 王娆
 * @LastEditTime: 2020-08-27 19:41:28
-->
<template>
  <div class="login">
    <div class="loginWrap">
      <el-form
        :model="loginForm"
        :rules="rules"
        ref="ruleForm"
        class="demo-ruleForm"
      >
        <el-form-item prop="user_name">
          <el-input v-model="loginForm.user_name" placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item prop="user_pwd">
          <el-input v-model="loginForm.user_pwd" placeholder="请输入用户密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleLogin">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { mapActions} from 'vuex'
export default {
  data () {
    return {
      loginForm: {
        user_name: '',
        user_pwd: ''
      },
      rules: {
        user_name: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 2, max: 20, message: '长度在 2 到 6 个字符', trigger: 'blur' }
        ],
        user_pwd: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    ...mapActions('Login', ['loginUser']),
    handleLogin () {
      this.loginUser(this.loginForm)
      sessionStorage.setItem('user_name',this.loginForm.user_name)
      sessionStorage.setItem('user_pwd',this.loginForm.user_pwd)
    }
  },
  mounted () {
    this.loginForm.user_name = sessionStorage.getItem('user_name')
    this.loginForm.user_pwd = sessionStorage.getItem('user_pwd')
  }
}
</script>

<style lang='scss' scoped>
.login {
  width: 100%;
  height: 100%;
  background: #000080;
  position: relative;
  box-sizing: border-box;
}
.loginWrap {
  width: 400px;
  height: 300px;
  border-radius: 4px;
  background: #fff;
  position: absolute;
  top: 20%;
  left: 56%;
  padding:40px 20px;
  .el-button{
    width:100%;
    margin-top: 30px;
  }
}
</style>
